<?php

App::uses('AppModel', 'Model');

class ForgotPassToken extends AppModel
{

    var $name = 'ForgotPassToken';

    public $belongsTo = array(
        'StudentUser' => array(
            'className' => 'StudentUser',
            'foreignKey' => 'student_user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

    public function save($data = null,$validate = true, $fieldList = array()) {
        $s = $this->sanitize($data);
        return parent::save($s);
    }

    function verify_token($token = null)
    {
        $arr = explode('|', $token);
        $result = $this->find('first', array(
                'conditions' => array('student_user_id' => $arr[0], 'token' =>$token, 'used' => 'No'),
                'recursive' => -1)
        );
        if ($result) {
            return array('status' => true, 'msg' => 'Token Verified', 'data' => $result);
        } else {
            return array('status' => false, 'msg' => 'Token Invalid');
        }
    }

    function update_token($data)
    {
        $result = $this->save($data);
        if ($result) {
            return array('status' => true, 'msg' => 'Token Updated');
        } else {
            return array('status' => false, 'msg' => 'Token Not Updated');
        }
    }
}